/**
 * @Author YuanYuan
 * @Date 2022/8/14
 * @Time 9:48
 */
class MyThread extends Thread {
    @Override
    public void run() {
        while (true) {

            System.out.println(1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

}
class MyRunnable implements Runnable {
    public static final long COUNT = 10_0000_0000L;
    @Override
    public void run() {
        int a = 0;
        for (int i = 0; i < COUNT; i++) {
            a++;
        }
    }
}
public class TestDemo {
    public static final long COUNT = 10_0000_0000L;
    public static void fun1() {
        long beg = System.currentTimeMillis();
        long a = 0;
        for (int i = 0; i < COUNT; i++) {
            a++;
        }
        a = 0;
        for (int i = 0; i < COUNT; i++) {
            a++;
        }
        System.out.println(System.currentTimeMillis()- beg + "ms") ;
    }
    public static void fun3() {
        Thread  thread = new Thread(()->{
            while (true) {
                System.out.println("阿巴阿巴");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"阿巴阿巴");
        thread.start();
    }
    public static void fun2() throws InterruptedException {
        Runnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable,"嘻嘻号线程");
        Thread thread1 = new Thread(myRunnable,"嘿嘿号线程");
        long beg = System.currentTimeMillis();

        thread.start();
        thread1.start();

        thread.join();
        thread1.join();
        long end = System.currentTimeMillis();
        System.out.println(end-beg + "ms");

    }

    public static void main(String[] args) {
        fun3();
    }
    public static void main2(String[] args) throws InterruptedException {
        fun1();
        fun2();
    }
    public static void main1(String[] args) {
        Thread myThread = new MyThread();
        Runnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
        //myThread.run();
        myThread.start();

        thread.start();

        Thread myThread0 = new MyThread() {
            @Override
            public void run() {
                System.out.println(3);
            }
        };

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(4);
            }
        });

        Thread thread2 = new Thread(()->{
            while (true) {
                System.out.println(5);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();

    }
}
